home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / Long Labels User Area.cpt / Long Labels User Area / Label.a next >
Text File  |  1989-03-10  |  19KB  |  624 lines

  1. ;This label.a file works with some of the new long label
  2. ;formats generated by MPW 3.0.  This is useful so you can
  3. ;find long labels in your code from TMON.  Since long labels
  4. ;didn't exist when TMON was originally written, proper
  5. ;long label support is only available in TMON Professional.
  6. ;
  7. ;Modified 12/7/88 to work with both old and new labels
  8. ;(as was originally intended for this version).
  9. ;
  10. ;Modified 3/10/89 by Paul F. Snively to correctly support
  11. ;MPW 3.0 frozen release long labels as well as "old-style
  12. ;MacsBug" eight-character labels.
  13.  
  14.         INCLUDE 'Labels.a'
  15.  
  16. CodeResources
  17.         ;Resources which may contain code.
  18.  
  19.         DC.L    ('CODE')
  20.         DC.L    ('CACH')        ;File system cache.
  21.         DC.L    ('CDEF')        ;Control defProc.
  22.         DC.L    ('cdev')        ;Control device.
  23.         DC.L    ('DRVR')        ;Driver.
  24.         DC.L    ('DSAT')        ;DS Alert code.
  25.         DC.L    ('FKEY')        ;Shift-Cmd code.
  26.         DC.L    ('FMTR')        ;Formatting code.
  27.         DC.L    ('INIT')        ;Initialization.
  28.         DC.L    ('LDEF')        ;List defProc.
  29.         DC.L    ('MBDF')        ;Menu Bar defProc.
  30.         DC.L    ('MDEF')        ;Menu defProc.
  31.         DC.L    ('NBPC')        ;Name-binding protocol (AppleTalk).
  32.         DC.L    ('PACK')        ;Package.
  33.         DC.L    ('PDEF')        ;Printing defProc.
  34.         DC.L    ('PROC')        ;Generic code.
  35.         DC.L    ('PATC')        ;Patches.
  36.         DC.L    ('PTCH')        ;Patches.
  37.         DC.L    ('SERD')        ;RAM serial driver.
  38.         DC.L    ('WDEF')        ;Window defProc.
  39.         DC.L    ('XCMD')        ;Hypercard external command.
  40.         DC.L    ('XFCN')        ;Hypercard external function.
  41.         DC.L    ('tcod')        ;Apple File Exchange.
  42.         DC.L    ('tprc')        ;Apple File Exchange.
  43.         DC.L    ('4NFS')        ;Apple File Exchange.
  44.         DC.L    ('MCMC')        ;Apple File Exchange.
  45.         DC.L    ('MCPD')        ;Apple File Exchange.
  46.         DC.L    ('MCMS')        ;Apple File Exchange.
  47.         DC.L    ('PDMC')        ;Apple File Exchange.
  48.         DC.L    ('PDPD')        ;Apple File Exchange.
  49.         DC.L    ('PDMS')        ;Apple File Exchange.
  50.         DC.L    ('MSMC')        ;Apple File Exchange.
  51.         DC.L    ('MSPD')        ;Apple File Exchange.
  52.         DC.L    ('MSMS')        ;Apple File Exchange.
  53.  
  54. ;This is a patch area primarily for those who do not have MPW and need
  55. ;to patch this list instead of changing the source and rebuilding.  If
  56. ;you want to add new resource types to this list, you can add them
  57. ;after the last valid type, replacing longwords of zero.  There must
  58. ;be one zero terminator (longword) to end this list.
  59.  
  60.         DC.L    0
  61.         DC.L    0
  62.         DC.L    0
  63.         DC.L    0
  64.         DC.L    0
  65.         DC.L    0
  66.  
  67.         ;######################
  68.         ;##             ##
  69.         ;##  Label routines  ##
  70.         ;##             ##
  71.         ;######################
  72.  
  73.  
  74. ;+--------------------------------------------------------+
  75. ;| Check if D2 is in a code resource, and, if it is,      |
  76. ;| attempt to find the name of the routine containing D2. |
  77. ;+--------------------------------------------------------+
  78. ;|
  79. ;|ENTRY: CodeLabelScan
  80. ;|
  81. ;|IN:    D2.L:    address to identify.
  82. ;|    D0.L:    0.
  83. ;|    D5.L:    if D2 is in a resource, offset from the resource beginning to D2.
  84. ;|    D6.L:    if D2 is in a resource, the resource type; otherwise, 0.
  85. ;|    D7.L:    Bits 0..15 contain the resource ID.  Bits 16..23 contain the value of _Inhibits.
  86. ;|    A4:    if D2 is in a resource, beginning address of the heap block.  (D2:-D5:)
  87. ;|    A3:    if D2 is in a resource, ending address of the heap block.  (D2:-D5:)
  88. ;|    A5:    ^Monitor's variables.
  89. ;|(D4 is initialized by the Monitor, but this routine does not use it.)
  90. ;|
  91. ;|OUT:    D0.L'=0   D2 could not be identified.
  92. ;|        D2.L'   D2.L:.
  93. ;|    D0.L'<>0  D2 was identified.
  94. ;|        D0.L'   first four letters of name.
  95. ;|        D1.L'   last four letters of name.
  96. ;|        A1'     address of the routine's beginning (the LINK instruction).
  97. ;|        D2.L'   D2.L:-A1'.
  98. ;|
  99. ;|Destroys D1,D3,A0,A1.
  100. ;|
  101.  
  102. CodeLabelScan
  103.         MOVEM.L D4/D5/D6/D7,-(SP)    ;Save registers.
  104.         LEA    CodeResources,A0
  105. CheckCodeTypes
  106.         MOVE.L    (A0)+,D1        ;Check next type.
  107.         BEQ.S    NoCodeLabel
  108.         CMP.L    D1,D6            ;Don't search for code routine names unless this is
  109.         BNE.S    CheckCodeTypes        ;a code segment.
  110.         MOVE.L    D2,D7            ;D7 will contain D2 truncated to an even value.
  111.         BCLR    #0,D7
  112.         MOVE.L    D7,A0
  113.         MOVE.L    A3,D3            ;D3 contains the number of words left to scan
  114.         SUB.L    D7,D3            ;before giving up at $800 or finishing at the end of
  115.         CMP.W    #$800,D3        ;the block.
  116.         BCS.S    @1
  117.         MOVE.W    #$800,D3
  118. @1        LSR.W    #1,D3
  119.         ADDQ.L    #2,D7            ;Increment the starting position pointer by 2.
  120. ExamineCode    MOVE.W    #$4E75,D1        ;D1.W:    RTS
  121.         MOVE.W    #$4ED0,D6        ;D6.W:    JMP (A0)
  122.         MOVE.W    LINKAx,D4        ;D4.W:    LINK A6,#____
  123.         BRA.S    SearchNextCodeLabel
  124. LoopNextCodeLabel
  125.         MOVE.W    (A0)+,D0        ;Get the next word.
  126.         CMP.W    D1,D0            ;Search for one of the above instructions.
  127.         BEQ.S    InvestigateLabel    ;If RTS or JMP (A0) is found, investigate further.
  128.         CMP.W    D6,D0
  129.         BEQ.S    InvestigateLabel
  130.         CMP.W    D4,D0
  131. SearchNextCodeLabel
  132.         DBEQ    D3,LoopNextCodeLabel    ;If the LINK is found first, exit with no label.
  133.         BNE.S    NoCodeLabel        ;If the LINK is the first instruction encountered,
  134.         CMPA.L    D7,A0            ;leave it as it is because it may be the beginning
  135.         BEQ.S    ExamineCode        ;of the subroutine.
  136. NoCodeLabel
  137.         MOVEQ    #0,D0            ;Pass back no label code.
  138. DoneCodeLabel
  139.         MOVEM.L (SP)+,D4/D5/D6/D7    ;Return.
  140.         RTS
  141.  
  142. InvestigateLabel
  143.         CMP.W    #4,D3            ;If there are less than eight bytes left to scan,
  144.         BCS.S    NoCodeLabel        ;it's not possible to have a full name here.
  145.         BSR.S    CheckUNLK        ;Check for an UNLK instruction before the RTS or
  146.         BNE.S    SearchNextCodeLabel    ;JMP (A0).  If not found, continue searching.
  147.         MOVE.B    (A0),D6
  148.         CMP.B    #$81,D6
  149.         BCS.S    CheckVeryLong
  150.         CMP.B    #$A0,D6
  151.         BCC.S    CheckTheLetters
  152.         ADDA.L    #1,A0
  153.         AND.B    #$7F,D6
  154.         CMP.B    #8,D6
  155.         BCS.S    @1
  156.         MOVEQ    #8,D6
  157. @1        MOVE.L    A1,-(A7)
  158.         MOVE.L    #'    ',-(A7)
  159.         MOVE.L    #'    ',-(A7)
  160.         MOVE.L    A7,A1
  161. @2        MOVE.B    (A0)+,(A1)+
  162.         SUBQ.B    #1,D6
  163.         BNE.S    @2
  164.         MOVEM.L    (A7)+,D0/D1/A1
  165.         BRA.S    FoundTheLetters
  166.  
  167. CheckVeryLong    CMP.B    #$80,D6
  168.         BNE.S    CheckTheLetters
  169.         ADDA.L    #2,A0
  170. CheckTheLetters    MOVEQ    #7,D6
  171. Check8Letters
  172.         ROL.L    #8,D0            ;Check the name to make sure that there are eight
  173.         ROL.L    #8,D1            ;letters of valid ASCII values present.
  174.         MOVE.B    D1,D0
  175.         MOVE.B    (A0)+,D1
  176.         CMP.B    #6,D6
  177.         BCS.S    @1
  178.         AND.B    #$7F,D1         ;Clear the high bit of the first and second bytes.
  179. @1        CMP.B    #' ',D1         ;Anything between $20 and $7E is valid.
  180.         BCS.S    NoCodeLabel
  181.         CMP.B    #$7F,D1
  182.         BCC.S    NoCodeLabel
  183.         DBRA    D6,Check8Letters
  184. FoundTheLetters    MOVE.L    D5,D3            ;A valid name has been found.  Now search backwards
  185.         LSR.L    #1,D3            ;for the LINK instruction.
  186.         MOVE.L    D7,A1
  187. @2        CMP.W    -(A1),D4
  188.         DBEQ    D3,@2
  189.         BNE.S    NoCodeLabel        ;If run out of the block, exit.
  190.         SUB.L    A1,D2            ;Otherwise give the offset in D2 and return
  191.         BRA.S    DoneCodeLabel        ;successfully.
  192.  
  193.  
  194. ;+-------------------------------------------------------+
  195. ;| Make sure that an UNLK A6 instruction exists no more  |
  196. ;| than ten words in front of A0.  Also make sure that     |
  197. ;| there is no LINK A6 between the UNLK A6 and A0.     |
  198. ;+-------------------------------------------------------+
  199. ;|
  200. ;|ENTRY: CheckUNLK
  201. ;|
  202. ;|IN:    A0:    Address from which to search.
  203. ;|
  204. ;|OUT:    Z flag' set if the conditions above satisfied, clear otherwise.
  205. ;|
  206. ;|Destroys nothing.
  207. ;|
  208.  
  209. CheckUNLK    MOVEM.L D0-D2/A0,-(SP)        ;Save registers.
  210.         MOVEQ    #9,D0            ;Search ten words.
  211.         MOVE.W    UNLKAx,D1
  212.         MOVE.W    LINKAx,D2
  213. @1        CMP.W    -(A0),D1        ;UNLK A6
  214.         BEQ.S    @2
  215.         CMP.W    (A0),D2            ;LINK A6,#____
  216.         DBEQ    D0,@1
  217.         MOVEQ    #-1,D0            ;If not found or LINK found first, clear Z flag.
  218. @2        MOVEM.L (SP)+,D0-D2/A0        ;Return (MOVEM preserves flags).
  219.         RTS
  220.  
  221.  
  222. ;+----------------------------------+
  223. ;| Find a given embedded routine    |
  224. ;| 8-character name in code blocks. |
  225. ;| See manual for details.        |
  226. ;+----------------------------------+
  227. ;|
  228. ;|ENTRY: CodeLabelFind
  229. ;|
  230. ;|IN:    D0.L:    first four characters of the name converted to upper case.
  231. ;|    D1.L:    last four characters of the name converted to upper case.
  232. ;|    D7.L:    bits 16..23 contain the value of _Inhibits.
  233. ;|    A5:    ^Monitor's variables.
  234. ;|
  235. ;|OUT:    D0.L'=0 the name has been found.
  236. ;|    D2.L'   the location of the routine that has the given name.
  237. ;|    D0.L'=D0.L: the name has not been found.
  238. ;|
  239. ;|Destroys D2,D3,A0,A1.
  240. ;|
  241.  
  242. CodeLabelFind
  243.         MOVEM.L D0/D1/D4-D7/A2-A4/A6,-(SP)
  244.         BTST    #16+3,D7        ;If can't scan resources, do nothing.
  245.         BNE    DoneCodeLabelFind
  246.         MOVE.L    SP,A6
  247.         MOVE.L    TopMapHndl,D1        ;Start with the first resource file.
  248. NextResourceFile
  249.         JSR    _NextCResFile        ;Check the next file.
  250.         BEQ    DoneCodeLabelFind    ;If there is none, no data will be found.
  251.         MOVE.L    A1,A3
  252.         MOVE.W    (A3)+,D6        ;D6 has the number of types+1.
  253.         BMI.S    NextResourceFile
  254. DoNextResourceType
  255.         MOVE.L    (A3)+,D2        ;Get the resource type.
  256.         ADDQ.W    #4,A3            ;Look for blocks of type proper type.
  257.         LEA    CodeResources,A4
  258. CheckCodeResourceTypes
  259.         MOVE.L    (A4)+,D0        ;Check next type.
  260.         BEQ.S    NotACodeResourceType
  261.         CMP.L    D0,D2            ;Don't search for code routine names unless this is
  262.         BEQ.S    IsACodeResourceType    ;a code segment.
  263.         BRA.S    CheckCodeResourceTypes
  264. NotACodeResourceType
  265.         MOVEQ    #-1,D0
  266. IsACodeResourceType
  267.         DBEQ    D6,DoNextResourceType    ;Check the next resource type.
  268.         BNE.S    NextResourceFile    ;If not found, scan the next file.
  269.         SWAP    D6            ;Put the count away in the high word.
  270.  
  271.         MOVE.W    -2(A3),D0
  272.         LEA    0(A1,D0.W),A2        ;Find the ID list and check for address errors.
  273.  
  274.         LSR.B    #1,D0
  275.         BCS.S    NextResourceFile
  276.  
  277.         MOVE.W    -4(A3),D6        ;D6 now has the number of IDs in the table.
  278.         BMI.S    NextResourceType
  279. DoNextResource
  280.         ADDQ.W    #8,A2
  281.         MOVE.L    (A2)+,A0        ;See if this resource is legally in memory.
  282.         BSR    IndirectA0
  283.         BCS.S    NextResource        ;NO.
  284.  
  285.         MOVE.L    -8(A0),D0
  286.         StripAddress    D0
  287.         MOVEQ    #$0F,D2
  288.         AND.B    -8(A0),D2        ;Subtract the size correction from the size.
  289.         SUB.L    D2,D0
  290.         MOVEQ    #8,D2
  291.         SUB.L    D2,D0
  292.         BMI.S    NextResource        ;If a negative number results, skip to the
  293.         LSR.L    #1,D0            ;next block.
  294.  
  295.         CMP.L    #$8000,D0
  296.         BLO.S    @1
  297.         MOVE.L    #$7FFF,D0
  298. @1
  299.         MOVE.W    LINKAx,D2        ;D2.W:    LINK A6,#____
  300.         MOVE.W    #$4E75,D3        ;D3.W:    RTS
  301.         MOVE.W    #$4ED0,D4        ;D4.W:    JMP (A0)
  302.         BRA.S    FindLink
  303. DoFindLink
  304.         CMP.W    (A0)+,D2        ;Search for a LINK instruction.
  305. FindLink
  306.         DBEQ    D0,DoFindLink
  307.         BNE.S    NextResource        ;Not found within the block.
  308. FindReturnUnlink
  309.         MOVE.L    A0,D7            ;Anchor the address and look for
  310.         MOVEQ    #-1,D5            ;Always set the flag to NE.
  311.         BRA.S    FindReturn        ;an RTS or JMP (A0).
  312. DoFindReturn
  313.         MOVE.W    (A0)+,D5
  314.         CMP.W    D5,D3
  315.         BEQ.S    CheckUnlink
  316.         CMP.W    D5,D4
  317.         BEQ.S    CheckUnlink
  318.         CMP.W    D5,D2            ;If another LINK is found first, restart this loop.
  319. FindReturn
  320.         DBEQ    D0,DoFindReturn
  321.         BNE.S    NextResource
  322.         BRA.S    FindReturnUnlink    ;Search again.
  323. CheckUnlink
  324.         BSR    CheckUNLK        ;Check for an UNLK instruction before the RTS or
  325.         BNE.S    FindReturn        ;JMP (A0).
  326.         BSR.S    CheckName
  327.         BNE.S    FindLink
  328. FoundCodeLabel
  329.         SUBQ.L    #2,D7            ;Return the code label in D2.
  330.         MOVE.L    D7,D2
  331.         CLR.L    (SP)            ;Clear D0 on the stack image.
  332. DoneCodeLabelFind
  333.         MOVEM.L (SP)+,D0/D1/D4-D7/A2-A4/A6
  334.         RTS
  335.  
  336. NextResource
  337.         DBRA    D6,DoNextResource    ;Examine the next block, or, if there are no more,
  338. NextResourceType
  339.         SWAP    D6            ;Bring the count back from the high word.
  340.         BRA    DoNextResourceType
  341.  
  342.  
  343. ;+---------------------------------------------------------------------------------+
  344. ;| Compare the names at (A0)+ and (A6)+.  Convert the name at (A0)+ to upper case  |
  345. ;| and clear the 7th bit in its first 2 characters for the purpose of comparison.  |
  346. ;| The name at (A6)+ is assumed to be in upper case, as it will be if it was       |
  347. ;| generated by the Monitor.  Both names must be eight characters long.        |
  348. ;+---------------------------------------------------------------------------------+
  349. ;|
  350. ;|ENTRY: CheckName
  351. ;|
  352. ;|IN:    A0:    string1, upper or lower case, 7th bit clear or set on first character.
  353. ;|    A6:    string2, upper case only, 7th bit clear.
  354. ;|
  355. ;|OUT:    Z flag' set if uppercase(string1)=string2
  356. ;|        clear otherwise.
  357. ;|
  358. ;|Destroys nothing.
  359. ;|
  360.  
  361. CheckName:    MOVEM.L D0/D1/A1/A2,-(SP)
  362.         MOVEQ    #0,D0
  363.         MOVE.B    (A0),D0
  364.         CMP.B    #$81,D0
  365.         BCS.S    OldCheckName
  366.         CMP.B    #$C0,D0
  367.         BCC.S    OldCheckName
  368.         SUB.B    #$80,D0
  369.         CMP.B    #8,D0
  370.         BCS.S    @1
  371.         MOVEQ    #8,D0
  372.         BRA.S    @2
  373. @1        CMP.B    #' ',0(A6,D0.W)
  374.         BNE.S    BadCheckName
  375. @2        SUBQ.B    #1,D0
  376.         MOVE.L    A0,A2
  377.         ADDQ.W    #1,A2
  378.         BRA.S    OldCheckName2
  379. OldCheckName:    MOVEQ    #7,D0            ;Compare eight characters.
  380.         MOVE.L    A0,A2
  381. OldCheckName2:    MOVE.L    A6,A1            ;Use copies of A0 and A6.
  382. @4        MOVEQ    #$7F,D1         ;Clear the high bit of the first character.
  383.         AND.B    (A2)+,D1
  384.         BRA.S    @3
  385. @1        CMP.B    #6,D0
  386.         BHS.S    @4
  387.         MOVE.B    (A2)+,D1
  388. @3        CMP.B    #'a',D1         ;Convert to upper case.
  389.         BCS.S    @2
  390.         CMP.B    #'z'+1,D1
  391.         BCC.S    @2
  392.         SUB.B    #$20,D1
  393. @2        CMP.B    (A1)+,D1        ;Compare and exit as soon as a mismatch is found or
  394.         DBNE    D0,@1            ;eight characters match.
  395. BadCheckName:    MOVEM.L (SP)+,D0/D1/A1/A2
  396.         RTS
  397.  
  398.  
  399. ;+---------------------------+
  400. ;| Find a given 8-character  |
  401. ;| label in the label table. |
  402. ;| See manual for details.   |
  403. ;+---------------------------+
  404. ;|
  405. ;|ENTRY: LabelFind
  406. ;|
  407. ;|IN:    D0.L:    first four characters of the name converted to upper case.
  408. ;|    D1.L:    last four characters of the name converted to upper case.
  409. ;|    D7:    bits 16..23 contain the value of _Inhibits.
  410. ;|    A5:    ^Monitor's variables.
  411. ;|
  412. ;|OUT:    D0.L'=0 the name has been found.
  413. ;|        D2.L'   the location of the routine that has the given name.
  414. ;|    D0.L'=D0.L: the name has not been found.
  415. ;|        D2.L'   unpredictable.
  416. ;|
  417. ;|Destroys D3,A0,A1.
  418. ;|
  419. ;|
  420. ;|ENTRY: LabelFind.
  421. ;|
  422. ;|Same as LabelFind except that if D2.B is nonzero, the subroutine will not check if the resource is in
  423. ;|memory for resource-relative labels.    Moreover, the address of the label will be passed back in
  424. ;|A0 if the label is found.  However the address of built-in labels is never returned.
  425. ;|
  426.  
  427. LabelFind:    MOVEQ    #0,D2
  428. LabelFind_:
  429.         MOVE.B    LabelEnabled,D3     ;If there is no table of labels, do nothing.
  430.         MOVEM.L D0/D1/D5/D6/A3/A4/A6,-(SP)
  431.         MOVE.L    SP,A6            ;A6 points to the saved name on the stack.
  432.         BMI.S    @20
  433.         MOVE.L    LabelTable,A0
  434.         SUBQ.W    #8,A0
  435.         MOVE.W    NumLabels,D3
  436.         MOVEQ    #-1,D0            ;Clear the Z flag.
  437.         BRA.S    @2
  438. @1        ADD.W    #16,A0            ;Check the names in the label table.
  439.         BSR    CheckName
  440. @2        DBEQ    D3,@1
  441.         BEQ.S    @21            ;If found, continue
  442. @20        MOVE.L    UALabelTable,A0     ;Point to built in label table.
  443.         SUBQ.L    #8,A0
  444.         MOVE.W    NumUALabels,D3
  445.         MOVEQ    #-1,D0
  446.         BRA.S    @22
  447. @23        ADD.W    #16,A0
  448.         BSR    CheckName
  449. @22        DBEQ    D3,@23
  450. @21        BNE.S    @10            ;If no match, exit.
  451.         MOVE.L    -(A0),D3        ;Determine whether this is an absolute or
  452.         MOVE.B    D2,D0            ;resource-relative label.
  453.         MOVE.L    -(A0),D2
  454.         TST.B    (A0)
  455.         BEQ.S    @3            ;If absolute, exit successfully.
  456.         TST.B    D0
  457.         BNE.S    @3            ;If supposed to pass back label address, exit now.
  458.         BTST    #16+3,D7        ;If resource-relative, resource scanning must not be
  459.         BNE.S    @10            ;inhibited!
  460.         SWAP    D3
  461.         JSR    _FindRes        ;Find the desired resource, and, if all is well,
  462.         TST.B    D0            ;add the offset to its beginning.
  463.         BNE.S    @10
  464.         CLR.W    D3
  465.         SWAP    D3
  466.         ADD.L    D3,D2
  467. @3
  468.         MOVE.L    UALabelTable,A1
  469.         CMP.L    A1,A0
  470.         BLO.S    @24
  471.         MOVE.L    UALabelTableEnd,A1
  472.         CMP.L    A1,A0
  473.         BHS.S    @24
  474.         MOVEQ    #0,D0
  475.         MOVE.L    D0,A0            ;Do NOT return a pointer for built-ins
  476. @24        CLR.L    (SP)            ;Clear D0 on the stack image.
  477. @10        MOVEM.L (SP)+,D0/D1/D5/D6/A3/A4/A6
  478. @11        RTS
  479.  
  480.  
  481. ;+------------------------------------+
  482. ;| Search the label table for a label |
  483. ;| that could be used to identify D2. |
  484. ;| The resource-relative labels will  |
  485. ;| be ignored if D6 is 0.          |
  486. ;+------------------------------------+
  487. ;|
  488. ;|ENTRY: LabelScan
  489. ;|
  490. ;|IN:    D2.L:    address to identify.
  491. ;|    D0.L:    0.
  492. ;|    D5.L:    if D2 is in a resource, offset from the resource beginning to D2.
  493. ;|    D6.L:    if D2 is in a resource, the resource type; otherwise, 0.
  494. ;|    D7.L:    Bits 0..15 contain the resource ID.  Bits 16..23 contain the value of _Inhibits.
  495. ;|    A4:    if D2 is in a resource, beginning address of the heap block.  (D2:-D5:)
  496. ;|    A3:    if D2 is in a resource, ending address of the heap block.  (D2:-D5:)
  497. ;|    A5:    ^Monitor's variables.
  498. ;|(D4 is initialized by the Monitor, but this routine does not use it.)
  499. ;|
  500. ;|OUT:    D0.L'=0   D2 could not be identified.
  501. ;|        D2.L'   D2.L:.
  502. ;|    D0.L'<>0  D2 was identified.
  503. ;|        D0.L'   first four letters of name.
  504. ;|        D1.L'   last four letters of name.
  505. ;|        D2.L'   offset from the label to D2.L.
  506. ;|
  507. ;|Destroys D1,D3,A0,A1.
  508. ;|
  509.  
  510. LabelScan:    CMP.L    OSTableStart,D2        ;Are we in the OS trap table?
  511.         BLO.S    @1
  512.         CMP.L    OSTableEnd,D2        ;Are we past the end of the trap table?
  513.         BLO.S    OSTableScan
  514. @1
  515.         CMP.L    ToolTableStart,D2    ;Are we in the Tool trap table?
  516.         BLO.S    LabelTableScan
  517.         CMP.L    ToolTableEnd,D2        ;Are we past the end of the trap table?
  518.         BLO.S    ToolTableScan
  519. LabelTableScan
  520.         MOVEM.L D4/D5,-(SP)        ;Save registers.
  521.         MOVEQ    #-1,D5            ;Assume that the best fit was 4294967295 bytes off.
  522.         MOVE.B    LabelEnabled,D3     ;If there is no table of labels, do nothing.
  523.         BMI.S    @20
  524.         MOVE.L    LabelTable,A0
  525.         MOVE.W    NumLabels,D3
  526.         BRA.S    @10
  527. @1        MOVE.L    A0,A1            ;Which type of a label is this?
  528.         TST.B    (A1)
  529.         BEQ.S    @2
  530.         CMP.L    (A1)+,D6        ;Resource-type.  The resource type and ID must
  531.         BNE.S    @5            ;match exactly.
  532.         CMP.W    (A1)+,D7
  533.         BNE.S    @5
  534.         MOVEQ    #0,D4            ;Get the address pointed by this label into D4.
  535.         MOVE.W    (A1)+,D4
  536.         ADD.L    A4,D4
  537.         BRA.S    @3
  538. @2        MOVE.L    (A1)+,D4        ;Absolute-type.  The given location must be below
  539.         CMP.L    (A1)+,D2        ;the maximum address given.  If it is, get the
  540.         BCC.S    @5            ;address pointed by this label into D4.
  541. @3        SUB.L    D4,D2
  542.         BCS.S    @4            ;Calculate the difference between D4 and the
  543.         CMP.L    D5,D2            ;location given, and check if this is a closest
  544.         BCC.S    @4            ;match.
  545.         MOVE.L    D2,D5
  546.         MOVE.L    (A1)+,D0        ;If so, copy the name into D0 and D1 and the
  547.         MOVE.L    (A1),D1         ;difference into D5.
  548. @4        ADD.L    D4,D2
  549. @5        ADD.W    #16,A0
  550. @10        DBRA    D3,@1
  551.         MOVE.L    UALabelTableEnd,A1    ;Check if we were scanning the built in table.
  552.         CMP.L    A0,A1
  553.         BEQ.S    @21            ;If so, we are done
  554. @20        MOVE.L    UALabelTable,A0
  555.         MOVE.W    NumUALabels,D3
  556.         BRA.S    @10
  557. @21        TST.L    D0            ;If a good label has been found, put the difference
  558.         BEQ.S    @11            ;into D2.
  559.         MOVE.L    D5,D2
  560. @11        MOVEM.L (SP)+,D4/D5        ;Restore registers.
  561. @12        RTS
  562.  
  563. OSTableScan
  564.         MOVE.L    OSTableStart,D1
  565.         MOVE.W    #$A000,D3        ;Set up for an OS trap.
  566.         BRA.S    TrapTableScan
  567. ToolTableScan
  568.         MOVE.L    ToolTableStart,D1
  569.         MOVE.W    #$A800,D3        ;Set up for a tool trap.
  570. TrapTableScan
  571.         MOVE.W    D2,D0            ;Calculate a trap number.
  572.         SUB.W    D1,D0            ;An offset into the trap table.
  573.         MOVE.W    D0,-(SP)
  574.         LSR.W    #2,D0            ;A trap number.
  575.         OR.W    D3,D0            ;A trap.
  576.         LEA    TrapNameBuffer+8,A0    ;A place to disassemble.
  577.         MOVE.L    #'    ',D1
  578.         MOVE.L    D1,-(A0)
  579.         MOVE.L    D1,-(A0)
  580.         BSR.S    DisA000Y
  581.         LEA    TrapNameBuffer,A0    ;Point to buffer again.
  582.         CMP.B    #'_',(A0)
  583.         BEQ.S    @2
  584.         LEA    TrapNameBuffer+7,A1
  585.         MOVEQ    #6,D1
  586. @1        MOVE.B    -(A1),1(A1)
  587.         DBRA    D1,@1
  588. @2        MOVEM.W    (SP)+,D2        ;Get the offset in D2.
  589.         MOVE.B    #'j',(A0)        ;Replace the underline with a j.
  590.         MOVE.L    (A0)+,D0
  591.         MOVE.L    (A0),D1
  592.         AND.L    #3,D2            ;Make that offset.
  593.         RTS
  594.         
  595. TrapNameBuffer    DCB.B    20,0            ;A buffer for trap names.
  596.  
  597.  
  598. ;+----------------------------------------------------+
  599. ;| This subroutine disassembles a single A000 trap.   |
  600. ;| The string has one of two formats:              |
  601. ;|  _name if the trap could be recognized to be name, |
  602. ;|  $Annn if the trap could not be recognized.          |
  603. ;+----------------------------------------------------+
  604. ;|
  605. ;|ENTRY: DisA000Y
  606. ;|
  607. ;|IN:    D0:    A000 trap to be disassembled (only the low 12 bits are significant).
  608. ;|    A0:    ^the text record for the instruction.
  609. ;|    
  610. ;|OUT:    A0'     1+^the last character of the string.
  611. ;|
  612. ;|Destroys A0-A1,D0-D2.
  613. ;|
  614.  
  615. DisA000Y:    MOVEM.L    D3/D4/A2,-(A7)
  616.         MOVE.L    A0,A2
  617.         MOVE.W    D0,D2
  618.         MOVEQ    #-1,D0            ;Don't include the hexadecimal digit
  619.         JSR    _CallDisA000        ;indicator after the trap name.
  620.         MOVEA.L    A2,A0
  621.         MOVEM.L    (A7)+,D3/D4/A2
  622.         RTS
  623.  
  624.